package com.ruoyi.zhgd.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.Map;

import com.ruoyi.zhgd.util.PageUtils;
import com.ruoyi.zhgd.util.Query;
import com.ruoyi.zhgd.domain.vo.GroutingProcessVo;
import com.ruoyi.zhgd.dto.GroutingResultDto;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhgd.domain.vo.GroutingResultVo;
import com.ruoyi.zhgd.domain.bo.GroutingResultBo;
import com.ruoyi.zhgd.service.IGroutingResultService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 压浆结果
 *
 * @author zyb
 * @date 2023-09-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhgd/znyj_result")
public class GroutingResultController extends BaseController {

    private final IGroutingResultService iGroutingResultService;

    /**
     * 查询压浆结果列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<GroutingResultVo> list(GroutingResultBo bo, PageQuery pageQuery) {
        return iGroutingResultService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出压浆结果列表
     */
    @SaCheckLogin
    @Log(title = "压浆结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(GroutingResultBo bo, HttpServletResponse response) {
        List<GroutingResultVo> list = iGroutingResultService.queryList(bo);
        ExcelUtil.exportExcel(list, "压浆结果", GroutingResultVo.class, response);
    }

    /**
     * 获取压浆结果详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<GroutingResultVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iGroutingResultService.queryById(id));
    }

    /**
     * 新增压浆结果
     */
    @SaCheckLogin
    @Log(title = "压浆结果", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody GroutingResultBo bo) {
        return toAjax(iGroutingResultService.insertByBo(bo));
    }

    /**
     * 修改压浆结果
     */
    @SaCheckLogin
    @Log(title = "压浆结果", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody GroutingResultBo bo) {
        return toAjax(iGroutingResultService.updateByBo(bo));
    }

    /**
     * 删除压浆结果
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @Log(title = "压浆结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iGroutingResultService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 压浆结果数据列表
     * @param params
     * @param pageNum
     * @param pageSize
     * @return
     */
    @SaCheckLogin
    @GetMapping("/resultList")
    public R resultList(@RequestParam Map<String,Object> params,
                        @RequestParam(value = "pageNum" , required = false) Integer pageNum,
                        @RequestParam(value = "pageSize" , required = false) Integer pageSize){
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page",pageNum);
        paramMap.put("limit",pageSize);
        PageUtils resultList = iGroutingResultService.resultList(new Query(paramMap).getPage(), params);
        return R.ok(resultList);
    }

    @GetMapping("/statisticAnalysis")
    public List<GroutingResultDto> statisticAnalysis(String linkCode){
       return iGroutingResultService.statisticAnalysis(linkCode);
    }

    /**
     * 压浆报表明细
     * @param params
     * @return
     */
    @SaCheckLogin
    @GetMapping("/reportDetail")
    public R reportDetail(@RequestParam Map<String,Object> params){
        return R.ok(iGroutingResultService.reportDetail(params));
    }

    /**
     * 压浆过程数据
     * @param bo
     * @param pageQuery
     * @return
     */
    @SaCheckLogin
    @GetMapping("/processData")
    public TableDataInfo<GroutingProcessVo> processData(GroutingResultBo bo, PageQuery pageQuery){
        return iGroutingResultService.processData(bo, pageQuery);
    }

    /**
     * echarts折线图
     * @param bo
     * @return
     */
    @SaCheckLogin
    @GetMapping("/processDataEcharts")
    public Map<String, List<String>> processDataEcharts(GroutingResultBo bo){
        return iGroutingResultService.processDataEcharts(bo);
    }

}
